library(xlsx)
library(ggplot2)
library(psych)

df<-read.table("dataset.csv", sep =",", header = TRUE)
#df<-read.xlsx("dataset.xlsx", 1)
df1<-df[-which(df$exclude =="yes"),]




df_us<-df1[which(df1$country=="African American"),]


df_us$New_Hb_abnormal<-"Normal"

ab_dx<-which(df_us$HGB<=11.5)
df_us$New_Hb_abnormal[ab_dx]<-"Abnormal"



df_th<-df1[which(df1$country=="Asian"),]

# Hb
#ls_us_normal<-lm(df_us$BC[which(df_us$New_Hb_abnormal =="Normal")] ~df_us$G6PD_HGB[which(df_us$New_Hb_abnormal =="Normal")])
A1<-cor(df_us$BC[which(df_us$New_Hb_abnormal =="Normal")] ,df_us$G6PD_HGB[which(df_us$New_Hb_abnormal =="Normal")])
#ls_us<-lm(df_us$BC ~df_us$G6PD_HGB)
A2<-cor(df_us$BC ,df_us$G6PD_HGB)
#summary(ls_us_normal)
#summary(ls_us)

#ls_th_normal<-lm(df_th$BC[which(df_th$New_Hb_abnormal =="Normal")] ~df_th$G6PD_HGB[which(df_th$New_Hb_abnormal =="Normal")])
A3<-cor(df_th$BC[which(df_th$New_Hb_abnormal =="Normal")] ,df_th$G6PD_HGB[which(df_th$New_Hb_abnormal =="Normal")])
A4<-cor(df_th$BC ,df_th$G6PD_HGB)
#ls_th<-lm(df_th$BC ~df_th$G6PD_HGB)
#summary(ls_th_normal)
#summary(ls_th)

# RBC
#ls_us_normal<-lm(df_us$BC[which(df_th$New_Hb_abnormal =="Normal")] ~df_us$G6PD_RBC[which(df_th$New_Hb_abnormal =="Normal")])
A5<-cor(df_us$BC[which(df_th$New_Hb_abnormal =="Normal")][seq(67)] ,df_us$G6PD_RBC[which(df_th$New_Hb_abnormal =="Normal")][seq(67)])
#ls_us<-lm(df_us$BC ~df_us$G6PD_RBC)
A6<-cor(df_us$BC ,df_us$G6PD_RBC)
#summary(ls_us_normal)
#summary(ls_us)

#ls_th_normal<-lm(df_th$BC[which(df_th$New_Hb_abnormal =="Normal")] ~df_th$G6PD_RBC[which(df_th$New_Hb_abnormal =="Normal")])
A7<-cor(df_th$BC[which(df_th$New_Hb_abnormal =="Normal")] ,df_th$G6PD_RBC[which(df_th$New_Hb_abnormal =="Normal")])
#ls_th<-lm(df_th$BC ~df_th$G6PD_RBC)
A8<-cor(df_th$BC ,df_th$G6PD_RBC)
#summary(ls_th_normal)
#summary(ls_th)

#####################################################  all

df_all<-rbind(df_th,df_us)


#ls_us_normal<-lm(df_all$BC[which(df_all$New_Hb_abnormal =="Normal")] ~df_all$G6PD_HGB[which(df_all$New_Hb_abnormal =="Normal")])
A9<-cor(df_all$BC[which(df_all$New_Hb_abnormal =="Normal")] ,df_all$G6PD_HGB[which(df_all$New_Hb_abnormal =="Normal")])
#ls_us<-lm(df_all$BC ~df_all$G6PD_HGB)
A10<-cor(df_all$BC ,df_all$G6PD_HGB)
#summary(ls_us_normal)
#summary(ls_us)

#ls_th_normal<-lm(df_all$BC[which(df_all$New_Hb_abnormal =="Normal")] ~df_all$G6PD_RBC[which(df_all$New_Hb_abnormal =="Normal")])
A11<-cor(df_all$BC[which(df_all$New_Hb_abnormal =="Normal")] ,df_all$G6PD_RBC[which(df_all$New_Hb_abnormal =="Normal")])
#ls_th<-lm(df_all$BC ~df_all$G6PD_RBC)
A12<-cor(df_all$BC ,df_all$G6PD_RBC)
summary(ls_th_normal)
summary(ls_th)

